package com.zx.bus.controller;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zx.bus.service.CustomerService;
import com.zx.bus.vo.CustomerVo;
import com.zx.sys.constast.SysConstast;
import com.zx.sys.utils.DataGridView;
import com.zx.sys.utils.ResultObj;

@RestController
@RequestMapping("customer")
public class CustomerController {
	
	@Autowired
	private CustomerService customerService;
	
	@RequestMapping("loadAllCustomer")
	public DataGridView loadAllCustomer(CustomerVo customerVo) {
		return this.customerService.queryAllCustomer(customerVo);
	}
	
	@RequestMapping("addCustomer")
	public ResultObj addCustomer(CustomerVo customerVo) {
		try {
			customerVo.setCreatetime(new Date());
			this.customerService.addCustomer(customerVo);
			return new ResultObj(SysConstast.CODE_SUCCESS, SysConstast.ADD_SUCCESS);
		} catch (Exception e) {
			e.printStackTrace();
			return new ResultObj(SysConstast.CODE_ERROR, SysConstast.ADD_ERROR);
		}
	}
	
	@RequestMapping("updateCustomer")
	public ResultObj updateCustomer(CustomerVo customerVo) {
		try {
			this.customerService.updateCustomer(customerVo);
			return new ResultObj(SysConstast.CODE_SUCCESS, SysConstast.UPDATE_SUCCESS);
		} catch (Exception e) {
			e.printStackTrace();
			return new ResultObj(SysConstast.CODE_ERROR, SysConstast.UPDATE_ERROR);
		}
	}
	
	@RequestMapping("deleteCustomer")
	public ResultObj deleteCustomer(CustomerVo customerVo) {
		try {
			this.customerService.deleteCustomer(customerVo.getIdentity());
			return new ResultObj(SysConstast.CODE_SUCCESS,SysConstast.DELETE_SUCCESS);
		} catch (Exception e) {
			e.printStackTrace();
			return new ResultObj(SysConstast.CODE_ERROR,SysConstast.DELETE_ERROR);
		}
	}

	@RequestMapping("deleteBatchCustomer")
	public ResultObj deleteBatchCustomer(CustomerVo customerVo) {
		try {
			this.customerService.deleteBatchCustomer(customerVo.getIds());
			return new ResultObj(SysConstast.CODE_SUCCESS,SysConstast.DELETE_SUCCESS);
		} catch (Exception e) {
			e.printStackTrace();
			return new ResultObj(SysConstast.CODE_ERROR,SysConstast.DELETE_ERROR);
		}
	}
}
